<template>
    <div class="login">
        <form>
            {{status}}
            <div v-show="status=='student'">studentId:<input v-model="sId" autocomplete="off" type="text" name="sId"></div>
            <div v-show="status=='teacher'">username:<input v-model="name" autocomplete="off" type="text" name="name"></div>
            <div>password:<input v-model="pwd" type="password" name="pwd"></div>
            <span @click="login(status)" class="subForm" >Submit</span>
        </form>

    </div>
</template>

<script>
    import {mapState} from 'vuex'
    import {studentlogin} from '../network/student'
    import {adminlogin} from '../network/student'

    export default {
        name: "login",
        computed: {
            ...mapState(['status'])
        },
        data() {
            return {
                sId:"",
                pwd:"",
                name:''
            }
        },
        methods: {
             login:function (status) {
                if (status=='student') {
                    studentlogin(this.sId, this.pwd).then(res => {
                        console.log(res.data)
                        if (res.data != "") {
                            this.$router.push('/querystudent')
                        }
                    })
                }   else {
                    adminlogin(this.name,this.pwd).then(res => {
                        console.log(res.data)
                        if (res.data != "") {
                            this.$store.commit('adminname',this.name)
                            this.$router.push('/home')
                        }else {
                            alert("教师账号或密码错误")
                        }
                    })
                }
             }

        }
        // "http://39.103.172.195:7777/student/login?sId="+this.sId+"pwd="+this.pwd
    }
</script>

<style scoped>

    .login form {
        width: 300px    ;
        height: 150px;
        position: absolute;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        /*top: ;*/
        left: 50%;
        transform: translateX(-50%);
        border: solid 1px #909193;
    }

    .login form > div {
        margin-bottom: 10px;
    }

    input {
        outline: none;
        border: none;
        border-bottom: 1px solid black;
        background-color: transparent;
        padding: 6px;
    }

    .subForm {

        cursor: pointer;
        padding: 5px 10px;
        border: solid 1px;
    }
</style>
